package cn.gong.jizhang.utils;

import cn.gong.jizhang.config.Configs;

import android.util.Log;

public class DebugUtils {
	public static final String TAG = "igeifu";
	public static final boolean ISTRACE = Configs.ISTRACE;

	private static void debug(String msg) {
		debug(TAG, msg);
	}

	private static void debug(String tag, String msg) {
		if (ISTRACE) {
			Log.i(tag, msg);
		}
	}
	
	public static void debug(String tag, int msg, Class clazz) {
		debug(tag, String.valueOf(msg), clazz);
	}
	
	public static void debug(String tag, long msg, Class clazz) {
		debug(tag, String.valueOf(msg), clazz);
	}

	public static void debug(String tag, String msg, Class clazz) {
		if (ISTRACE) {
			debug(tag, msg + " class:" + clazz.getName());
		}
	}
	
	public static void debug(int msg, Class clazz) {
		debug(String.valueOf(msg), clazz);
	}
	
	public static void debug(long msg, Class clazz) {
		debug(String.valueOf(msg), clazz);
	}

	public static void debug(String msg, Class clazz) {
		if (ISTRACE) {
			debug(msg + " class:" + clazz.getName());
		}
	}

	private static void error(String tag, String msg) {
		if (ISTRACE) {
			Log.w(tag, msg);
		}
	}

	private static void error(String msg) {
		error(TAG, msg);
	}

	public static void error(Throwable e) {
		error("错误:");
		error("Caused by:" + e.toString());
		for (StackTraceElement stackTraceElement : e.getStackTrace()) {
			error(stackTraceElement.toString());
		}
	}

	public static void exception(Exception e) {
		error("异常:");
		error("Caused by:" + e.toString());
		for (StackTraceElement stackTraceElement : e.getStackTrace()) {
			error(stackTraceElement.toString());
		}
	}

	public static void exception(String tag, Exception e) {
		error(tag, "异常:");
		error(tag, "Caused by:" + e.toString());
		for (StackTraceElement stackTraceElement : e.getStackTrace()) {
			error(tag, stackTraceElement.toString());
		}
	}

	public static void isNull(String name, Object obj, Class clazz) {
		if (ISTRACE) {
			if (obj == null) {
				Log.i(TAG, name + ":是空 class:" + clazz.getName());
			} else {
				Log.i(TAG, name + ":不是空 class:" + clazz.getName());
			}
		}
	}
}
